package cn.jsoup;

import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;

import java.io.File;
import java.io.IOException;

public class jsoupDemo3 {
    public static void main(String[] args) throws IOException {
        String path = jsoupDemo3.class.getClassLoader().getResource("student.xml").getPath();
        //获取html路径
        Document document = Jsoup.parse(new File(path), "UTF-8");
        //将html文件进行解析
        Elements name = document.select("name");
        ///通过属性选择器选择标签
        System.out.println(name);//输出属性
        System.out.println("----------");
        Elements select = document.select("#itcast");
        //通过id选择器选择属性标签
        Elements select1 = document.select("student[number=\"itcast_0001\"]");//[attr="val"]

        //通过属性标签选择标签
        System.out.println(select1);
        System.out.println("----------");
        Elements select2 = document.select("student[number=\"itcast_0001\"]>age");
        //通过直接子类选择器选择标签
        System.out.println(select2);

    }
}
